package com.wanghua.spring.test.i18n;

import java.text.DateFormat;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;

//显示全球时间
public class timeZonei18n {
    public static void main(String[] args) {
        System.out.println("现在时刻：" + TimeZone.getDefault().getDisplayName() + " " + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.DEFAULT).format(new Date()));
        String[] avaiIDs = TimeZone.getAvailableIDs();  //获取所有可用的时区

        TimeZone timeZone1 = TimeZone.getTimeZone(avaiIDs[0]);
        System.out.print(timeZone1.getID() + " | ");                          //时区ID
        System.out.print(timeZone1.getDisplayName() + " | ");                 //时区
        System.out.print(timeZone1.getRawOffset() / 60 / 60 / 1000 + " | ");  //时差
        TimeZone.setDefault(timeZone1);                                        //设置时区，以显示设置时区的当前时间
        Calendar calendar = Calendar.getInstance();
        System.out.print((new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(calendar.getTime()));
        System.out.println();

        TimeZone timeZone2 = TimeZone.getTimeZone(avaiIDs[1]);
        System.out.print(timeZone2.getID() + " | ");
        System.out.print(timeZone2.getDisplayName() + " | ");
        System.out.print(timeZone2.getRawOffset() / 60 / 60 / 1000 + " | ");
        TimeZone.setDefault(timeZone2);
        Calendar calendar2 = Calendar.getInstance();
        System.out.print((new SimpleDateFormat("yyyy-MM-dd hh:mm:ss")).format(calendar2.getTime()));
        System.out.println();
    }
}
